import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:native_dart_package/native_dart_package.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/components/yt_expandable_tree/yt_expandable_tree.dart';
import 'package:yt_devops/components/yt_multi_column_picker/model/yt_multi_column_model.dart';
import 'package:yt_devops/components/yt_multi_column_picker/yt_multi_column_picker/yt_multi_column_picker_view.dart';
import 'package:yt_devops/resources/resources.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'select_product_type_page_controller.dart';

class SelectProductTypePageView
    extends GetView<SelectProductTypePageController> {
  const SelectProductTypePageView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarWidget.defaultAppBar(ResKey.productType.tr),
      backgroundColor: Colors.white,
      body: GetBuilder<SelectProductTypePageController>(
        builder: (controller) => Column(
          children: [
            Expanded(
                child: controller.tree == null
                    ? Gaps.empty
                    : YtMultiColumnPicker(
                        key: controller.brnMultiColumnPickerKey,
                        controller.tree!,
                        defaultFocusedIndexes: controller.selectedIndexes,
                        onModelTap: controller.onEntityTap,
                      )
                //  Row(
                //   children: [
                //     controller.treeList.isEmpty
                //         ? Gaps.empty
                //         : SizedBox(
                //             width: 140,
                //             child: YtExpandableTree(
                //               treeData: controller.treeList,
                //               isSearch: false,
                //               checkedValues: [],
                //               backgroudColor: Color(0xFFF6F7FB),
                //               showLine: false,
                //               selectedValues: controller.selectedValues.isEmpty
                //                   ? []
                //                   : [controller.selectedValues[0].value],
                //               onSelect: (index, newVal) {
                //                 controller.selectList =
                //                     (newVal as MultiColumnModel).selectList;
                //                 controller.selectedValues
                //                   ..clear()
                //                   ..add(newVal);
                //                 controller.update();
                //               },
                //             ),
                //           ),
                //     Expanded(
                //       child: YtExpandableTree(
                //         isSearch: false,
                //         multiple: false,
                //         showLine: false,
                //         treeData: controller.selectList,
                //         checkedValues: controller.checkedValues.isEmpty
                //             ? []
                //             : [controller.checkedValues[0].value],
                //         onValueChanged: (newVal) {
                //           controller.checkedValues.clear();
                //           if (newVal.isNotEmpty) {
                //             controller.checkedValues.add(newVal.last);
                //           }

                //           controller.update();
                //         },
                //       ),
                //     ),
                //     Gaps.hGap16
                //   ],
                // ),
                ),
            // Expanded(
            //   key: controller.ekey,
            //   child: controller.entity != null
            //       ? BrnMultiColumnPicker(
            //           key: controller.brnMultiColumnPickerKey,
            // 0x           maxHeight: controller.maxHeigt,
            //           pickerTitleConfig:
            //               const BrnPickerTitleConfig(showTitle: false),
            //           themeData: BrnPickerConfig(itemHeight: 48),
            //           entity: controller.entity!,
            //           showSelectedCount: true,
            //           defaultFocusedIndexes: const [0, 1, 1],
            //           onEntityTap: controller.onEntityTap,
            //         )
            //       : Gaps.empty,
            // ),
            Container(
              padding:
                  EdgeInsets.only(bottom: 34, left: 20.w, right: 20.w, top: 16),
              decoration: const BoxDecoration(
                  color: Colors.white,
                  boxShadow: [BoxShadow(color: Colour.shadowColor)]),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Gaps.line,
                  SizedBox(
                    child: GestureDetector(
                      onTap: () {
                        controller.reset();
                      },
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Image.asset(
                            ImageAssets.iconRenew,
                            width: 20.w,
                            height: 20.h,
                          ),
                          Text(
                            ResKey.reset.tr,
                            style: TextStyle(
                              color: Colour.mainTextColor,
                              fontSize: 14.sp,
                              fontWeight: FontWeight.w500,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                  Expanded(
                    child: Container(
                      margin: EdgeInsets.only(left: 18.w),
                      child: BrnBigMainButton(
                        title: ResKey.confirm.tr,
                        onTap: () {
                          Get.back(
                            result: controller.selectedEntity ?? {'id': null},
                          );
                        },
                      ),
                    ),
                  ),
                ],
              ),
            ),
            // BrnBottomButtonPanel(
            //   mainButtonName: ResKey.confirm.tr,
            //   mainButtonOnTap: () {
            //     Get.back(result: controller.selectedEntity);
            //   },
            //   iconButtonList: [
            //     //构造Icon按钮
            //     BrnVerticalIconButton(
            //       name: ResKey.reset.tr,
            //       iconWidget: Image.asset(
            //         ImageAssets.iconRenew,
            //       ),
            //     )
            //   ],
            // ),
          ],
        ),
      ),
    );
  }
}
